home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / COLM.ICN < prev    next >
Text File  |  1992-09-28  |  5KB  |  130 lines

  1. ############################################################################
  2. #
  3. #    File:     colm.icn
  4. #
  5. #    Subject:  Program to arrange data into columns
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     December 5, 1989
  10. #
  11. ###########################################################################
  12. #
  13. #  Colm -- Arrange data into columns.
  14. #
  15. #  Program  to  arrange  a  number  of  data items,  one per  line, into
  16. #  multiple  columns.  Items are arranged in column-wise order, that is,
  17. #  the sequence runs down the first column, then down the second, etc.
  18. #
  19. #  If a  null line appears in the input stream, it  signifies a break in
  20. #  the list,  and  the following  line is  taken  as  a  title  for  the
  21. #  following  data items.  No  title precedes  the initial  sequence  of
  22. #  items.
  23. #
  24. #  Usage:
  25. #
  26. #       colm [-w line_width] [-s space_between] [-m min_width]
  27. #               [-t tab_width] [-x] [-d] [file ...]
  28. #
  29. #  The parameters are:
  30. #
  31. #       line_width:     the maximum width allowed for output lines
  32. #                       (default: 80).
  33. #       space_between:  minimum number of spaces between items
  34. #                       (default: 2).
  35. #       min_width:      minimum width to be printed for each entry
  36. #                       (default: no minimum).
  37. #       tab_width:      tab width used to entab output lines.
  38. #                       (default: no tabs).
  39. #       -x              print items in row-wise order rather than
  40. #                       column-wise.
  41. #       -d (distribute) distribute columns throughout available width.
  42. #
  43. #  The command "colm -h" generates "help" text.
  44. #
  45. #  This is a  general utility,  but  it  was  written and tailored for a
  46. #  specific purpose:
  47. #
  48. #  This  utility  was written  to rearrange the file name  list from the
  49. #  Macintosh  Programmer's   Workshop  "Files"  command  into   a   more
  50. #  convenient  format.  "Files" lists  file  names in a  single  column.
  51. #  This program  takes  the  list  produced by  "Files"  and  outputs  a
  52. #  multi-column  list.  The  names  are  listed  vertically within  each
  53. #  column, and  the column width is computed dynamically  depending upon
  54. #  the sizes  of the  names listed.  A  recommendation  is  to create  a
  55. #  command file "lc" (List in Columns) as follows:
  56. #
  57. #       Files {"Parameters"} | colm
  58. #
  59. #  The output from  the  Files command  is "piped" to the "colm" program
  60. #  (this program), which prints its list in the current window.
  61. #
  62. #  By  putting both  the "lc"  command  file and the "colm" program into
  63. #  your {MPW}Tools folder, "lc" can be conveniently issued  as a command
  64. #  at any time, using the same parameters as the "Files" command.
  65.  
  66. link options, colmize
  67.  
  68. procedure main(arg)
  69.    local usage, help, opt, rowwise, distribute, maxcols, space, minwidth
  70.    local tabwidth, f, entries, entry
  71.    #
  72.    #  Define usage and help strings.
  73.    #
  74.    usage := "_
  75.    Usage:\tcolm [-w line_width] [-s space_between] [-m min_width]\n_
  76.         \t\t[-t tab_width] [-x] [file ...]\n_
  77.         \tcolm -h  for help"
  78.    help := "_
  79.         \tline_width:\tthe maximum width allowed for output lines\n_
  80.                     \t\t\t(default: 80).\n_
  81.         \tspace_between:\tminimum number of spaces between items\n_
  82.                     \t\t\t(default: 2).\n_
  83.         \tmin_width:\tminimum width to be printed for each entry\n_
  84.                     \t\t\t(default: no minimum).\n_
  85.         \ttab_width:\ttab width used to print output lines.\n_
  86.                     \t\t\t(default: no tabs).\n_
  87.         \t-x\t\tprint items in row-wise order rather than\n_
  88.                     \t\t\tcolumn-wise.\n_
  89.         \t-d (distribute)\tdistribute columns throughout available width."
  90.    #
  91.    #  Process command line options.
  92.    #
  93.    opt := options(arg,"hxdw+s+m+t+")
  94.    if \opt["h"] then write(usage,"\n\n",help) & exit()
  95.    rowwise := opt["x"]
  96.    distribute := opt["d"]
  97.    maxcols := \opt["w"] | 80
  98.    space := \opt["s"] | 2
  99.    minwidth := \opt["m"] | 0
  100.    tabwidth := (\opt["t"] | 0) + 1
  101.    if tabwidth = 1 then entab := 1
  102.    if *arg = 0 then arg := [&input]
  103.    #
  104.    #  Loop to process input files.
  105.    #
  106.    while f := get(arg) do {
  107.       f := (&input === f) | open(f) | stop("Can't open ",f)
  108.       #
  109.       #  Loop to process input groups (separated by empty lines).
  110.       #
  111.       repeat {
  112.      entries := []
  113.      #
  114.      #  Loop to build a list of non-empty lines of an input file.
  115.      #
  116.      while entry := "" ~== read(f) do {
  117.         put(entries,entry)
  118.         }
  119.      #
  120.      #  Now write the data in columns.
  121.      #
  122.      every write(entab(colmize(entries,maxcols,space,minwidth,
  123.            rowwise,distribute),tabwidth))
  124.      write("\n",read(f)) | break       # print the title line, if any
  125.      }
  126.       close(f)
  127.       write()
  128.       }
  129. end
  130.